<!doctype html>
<html lang="en">
<head>
    <meta charset="utf-8" />
    <base href="${request.contextPath}/"/>
    <link rel="icon" type="image/png" href="assets/img/favicon.ico">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" />
    <title>质量追溯</title>
    <meta content='width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0' name='viewport' />
    <meta name="viewport" content="width=device-width" />
    <!-- Bootstrap core CSS     -->
    <link href="product/css/bootstrap.min.css" rel="stylesheet" />
    <!-- Animation library for notifications   -->
    <link href="product/css/animate.min.css" rel="stylesheet"/>
    <!--  Light Bootstrap Table core CSS    -->
    <link href="product/css/light-bootstrap-dashboard.css" rel="stylesheet"/>
    <!--  CSS for Demo Purpose, don't include it in your project     -->
    <link href="product/css/demo.css" rel="stylesheet" />
    <link href="product/css/zhiLiangTouSu.css" rel="stylesheet" />
    <!--     Fonts and icons     -->
    <link href="product/css/fonts.googleapis.com.css" rel="stylesheet">
    <link href="product/css/font-awesome.min.css" rel="stylesheet">
    <link href="product/css/pe-icon-7-stroke.css" rel="stylesheet" />
    <!--
        0.引入jquery,因为页面报错,先导入jquery
        1.引入提示插件
        2.还是不好使，因为下面有其他js的问题，删了其他js好使了
        3.比较纯净只是调用了必须要用的东西
        4.官方只是让调用了webupload.js和webuploader.css
        5.我们引入的是fileupload.js 这个里面引入了官方让进入的必须的两个文件
        6.
    -->
    <script type="text/javascript" src="product/js/jquery.min.js"></script>
    <script src="product/layer/layer.js"></script>
    <script type="text/javascript" src="product/webuploader/fileupload.js"></script>

</head>
<body>
<div class="wrapper">
    <!--侧导航-->
    <#include '/common/daohang.html' />
    <!--内容区域-->
    <div class="main-panel">
        <nav class="navbar navbar-default navbar-fixed">
            <div class="container-fluid">
                <div class="navbar-header">
                    <a class="navbar-brand" href="#">质量投诉</a>
                </div>
                <div class="collapse navbar-collapse">
                    <ul class="nav navbar-nav navbar-right">
                        <li>
                            <a href="Traceability/suYuan/${code !''}/${id !''}/{type!''}">
                                质量追溯首页
                            </a>
                        </li>
                        <li>
                            <a href="index.html">
                                退出
                            </a>
                        </li>
                    </ul>
                </div>
            </div>
        </nav>
        <!--更换的区域-->

        <div class="content">
            <div class="container-fluid">
                <div class="row">
                    <div class="col-md-12">
                        <div class="card">
                            <div class="header">
                                <h4 class="title">质量投诉</h4>
                            </div>
                            <div class="content">
                                <form id="form">
                                    <div class="row">
                                        <div class="col-md-4">
                                            <div class="form-group">
                                                <label>企业名称</label>
                                                <input type="text" name="company" class="form-control" readonly placeholder="企业名称" >
                                                <input type="hidden" name="companyId">
                                            </div>
                                        </div>
                                        <div class="col-md-4">
                                            <div class="form-group">
                                                <label>产品名称</label>
                                                <input type="text" name="product" class="form-control" readonly placeholder="产品名称" >
                                                <input type="hidden" name="productId">
                                            </div>
                                        </div>
                                        <div class="col-md-4">
                                            <div class="form-group">
                                                <label>追溯码</label>
                                                <input type="text" name="traceabilityCode" class="form-control" readonly placeholder="溯源码" >
                                            </div>
                                        </div>
                                    </div>

                                    <div class="row">
                                        <div class="col-md-4">
                                            <div class="form-group">
                                                <label>购买信息</label>
                                                <input type="text" name="buyMsg" class="form-control" placeholder="请输入购买信息" >
                                            </div>
                                        </div>
                                        <div class="col-md-4">
                                            <div class="form-group">
                                                <label>购买商家</label>
                                                <input type="text" name="buyStore" class="form-control" placeholder="请输入购买商家">
                                            </div>
                                        </div>
                                        <div class="col-md-4">
                                            <div class="form-group">
                                                <label>购买厂家</label>
                                                <input type="text" name="buyFactory" class="form-control" placeholder="请输入购买厂家" >
                                            </div>
                                        </div>
                                    </div>

                                    <div class="row">
                                        <div class="col-md-6">
                                            <div class="form-group">
                                                <label>购买数量</label>
                                                <input type="text" name="buyNum" class="form-control" placeholder="请输入购买数量" >
                                            </div>
                                        </div>
                                        <div class="col-md-6">
                                            <div class="form-group">
                                                <label>联系电话</label>
                                                <input type="text" name="telephone" class="form-control" placeholder="请输入联系电话" >
                                            </div>
                                        </div>

                                    </div>

                                    <div class="row">
                                        <div class="col-md-6">
                                            <div class="form-group">
                                                <label>所在城市</label>
                                                <input type="text" name="city" class="form-control" placeholder="请输入所在城市" >
                                            </div>
                                        </div>
                                        <div class="col-md-6">
                                            <div class="form-group">
                                                <label>投诉类型</label>
                                                <select name="complainType" class="form-control">
                                                    <option value="轻微">轻微</option>
                                                    <option value="一般">一般</option>
                                                    <option value="严重">严重</option>
                                                </select>
                                            </div>
                                        </div>
                                     <!--   <div class="col-md-4">
                                            <div class="form-group">
                                                <label>受理人</label>
                                                <select class="form-control">
                                                    <option value="企业">企业</option>
                                                    <option value="饶河县市场监督管理局">饶河县市场监督管理局</option>
                                                </select>
                                            </div>
                                        </div>-->
                                    </div>
                                    <div class="row">
                                        <div class="col-md-12">
                                            <div class="form-group">
                                                <label>上传附件</label>
                                                <div id="zltsfile"></div>
                                                <input id="zltsfiles"name="zltsfiles" type="hidden" >
                                            </div>
                                        </div>
                                    </div>

                                    <div class="row">
                                        <div class="col-md-12">
                                            <div class="form-group">
                                                <label>投诉内容</label>
                                                <textarea rows="5" name="complainContent" class="form-control" placeholder="请简要描述您要投诉的内容" ></textarea>
                                            </div>
                                        </div>
                                    </div>

                                    <button type="button" id="submit" class="btn btn-info btn-fill " style="margin-right: 20px;">信息提交</button>
                                    <button type="reset" class="btn btn-info btn-default ">信息重置</button>
                                    <div class="clearfix"></div>
                                </form>
                            </div>
                        </div>
                    </div>


                </div>



            </div>
        </div>
    </div>
</div>
</body>

<script>
    $(document).ready(function(){
        $("#zltsfile").filePowerWebUpload({fileNum:0,fileNumLimit:2,type:"file",fileName:"zltsfile" });
    });
    //提交表单的时候执行一下也就是把值给赋值到form表单的元素里面
    function upload(){
        var fileurls = document.getElementsByName("zltsfile");
        var fileurl = '';
        for(var i=0;i < fileurls.length; i++){
            fileurl += fileurls[i].value + ",";
        }
        $("#zltsfiles").val(fileurl);
    }
</script>


<script type="text/javascript">
    var id = "${id}";
    var code = "${code}";
    var type = "${type}";
    $(document).ready(function(){

        $("#submit").click(function () {
                if( $("input[name='buyMsg']").val() == ""||  $("input[name='buyMsg']").val().length ==0){
                    layer.msg('购买信息不能为空',{time:2000,icon:5,shift:6},function () {});
                    $("input[name='buyMsg']").focus();
                    return;
                }

                if( $("input[name='buyStore']").val() == ""||  $("input[name='buyStore']").val().length ==0){
                    layer.msg('购买商家不能为空',{time:2000,icon:5,shift:6},function () {});
                    $("input[name='bugStore']").focus();
                    return;
                }
                if( $("input[name='buyFactory']").val() == ""||  $("input[name='buyFactory']").val().length ==0){
                    layer.msg('购买厂家不能为空',{time:2000,icon:5,shift:6},function () {});
                    $("input[name='bugFactory']").focus();
                    return;
                }
                if( $("input[name='buyMsg']").val() == ""||  $("input[name='buyMsg']").val().length ==0){
                    layer.msg('购买信息不能为空',{time:2000,icon:5,shift:6},function () {});
                    $("input[name='bugMsg']").focus();
                    return;
                }
                if( $("input[name='buyNum']").val() == ""||  $("input[name='buyNum']").val().length ==0){
                    layer.msg('购买数量不能为空',{time:2000,icon:5,shift:6},function () {});
                    $("input[name='bugNum']").focus();
                    return;
                }
                if( $("input[name='telephone']").val() == ""||  $("input[name='telephone']").val().length ==0){
                    layer.msg('联系电话不能为空',{time:2000,icon:5,shift:6},function () {});
                    $("input[name='telephone']").focus();
                    return;
                }
                if( $("input[name='city']").val() == ""||  $("input[name='city']").val().length ==0){
                    layer.msg('所在城市不能为空',{time:2000,icon:5,shift:6},function () {});
                    $("input[name='city']").focus();
                    return;
                }

                if( $("select[name='complainType']").val() == ""||  $("select[name='complainType']").val().length ==0){
                    layer.msg('投诉类型不能为空',{time:2000,icon:5,shift:6},function () {});
                    $("select[name='complainType']").focus();
                    return;
                }
                if( $("textarea[name='complainContent']").val() == ""||  $("textarea[name='complainContent']").val().length ==0){
                    layer.msg('投诉内容不能为空',{time:2000,icon:5,shift:6},function () {});
                    $("textarea[name='complainContent']").focus();
                    return;
                }
                //保存之前赋值
                upload();
                var loadingIndex =null;
                $.ajax({
                    url:"qualityComplaints/saveForm",
                    type:"POST",
                    data:$("#form").serialize(),
                    beforeSend:function () {
                        loadingIndex = layer.msg("处理中",{icon:16});
                    },
                    success:function (result) {
                        layer.close(loadingIndex);
                        if(result.code ==200){
                            layer.msg('保存成功,我们会尽快处理您的投诉！',{time:1000,icon:6},function () {
                                 window.location.href = "Traceability/suYuan/${code !''}/${id !''}/{type!''}";
                            });
                        }else{
                            layer.msg('保存失败，请联系管理员！',{time:2000,icon:5,shift:6},function () {
                                //弹出框关闭之后干的事情
                            });
                        }
                    }

                })
            });
        //发送ajax加载数据并赋值,传入参数产品id,
        function init() {
            $.ajax({
                url:"qualityComplaints/getInformation",
                type:"POST",
                data:{
                    "id":id
                },
                success:function (result) {
                    //将查出来的信息，用页面检查的方式查找id,给他们赋值就可以了
                    //从文档的属性中可以看到，选中用数组赋值
                    var productDisplay = result.data;
                    //赋值前几项
                    document.getElementsByName("company")[0].defaultValue = productDisplay.enterpriseName;
                    document.getElementsByName("companyId")[0].defaultValue = productDisplay.affiliatedEnterprises;
                    document.getElementsByName("product")[0].defaultValue = productDisplay.productName;
                    document.getElementsByName("productId")[0].defaultValue = productDisplay.ywId;
                    document.getElementsByName("traceabilityCode")[0].defaultValue = productDisplay.traceabilityCode;
                }
            })
        }

        init();

    });
</script>

</html>
